home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / ImageViewer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  5.0 KB  |  169 lines

  1. package symantec.itools.db.awt;
  2.  
  3. import java.applet.Applet;
  4. import java.awt.Canvas;
  5. import java.awt.Component;
  6. import java.awt.Container;
  7. import java.awt.Graphics;
  8. import java.awt.Image;
  9. import java.awt.MediaTracker;
  10. import java.awt.Toolkit;
  11. import java.io.InputStream;
  12. import java.net.URL;
  13. import symantec.itools.awt.image.StreamImageSource;
  14. import symantec.itools.db.pro.ProjBinder;
  15. import symantec.itools.db.pro.ProjLink;
  16. import symantec.itools.db.pro.RelationView;
  17. import symjava.sql.SQLException;
  18.  
  19. public class ImageViewer extends Canvas implements ProjLink {
  20.    Image image;
  21.    ProjBinder m_ProjBinder;
  22.    // $FF: renamed from: is java.io.InputStream
  23.    InputStream field_0;
  24.    int imageType = 1;
  25.    private boolean m_DynamicUpdate = true;
  26.    private boolean m_displayWhileLoading = false;
  27.    private int m_treatBlankAs;
  28.    private boolean m_isImageTheRightImage = true;
  29.    private boolean m_isBaseUrlTheRightBaseUrl = false;
  30.  
  31.    public ImageViewer() {
  32.    }
  33.  
  34.    public ImageViewer(URL base) {
  35.       StreamImageSource.setBaseUrl(base);
  36.    }
  37.  
  38.    public static void setBaseUrl(URL base) {
  39.       StreamImageSource.setBaseUrl(base);
  40.    }
  41.  
  42.    public void setBinding(RelationView relView, String projection) {
  43.       try {
  44.          int projectionNumber = relView.findProjByName(projection);
  45.          relView.bindProj(projectionNumber, this);
  46.       } catch (SQLException e) {
  47.          System.out.println(((Throwable)e).getMessage());
  48.       }
  49.    }
  50.  
  51.    public void setDisplayOption(boolean dOption) {
  52.       if (dOption) {
  53.          this.m_displayWhileLoading = true;
  54.       } else {
  55.          this.m_displayWhileLoading = false;
  56.       }
  57.    }
  58.  
  59.    public void setImageType(int type) {
  60.       this.imageType = type;
  61.    }
  62.  
  63.    public void init() {
  64.       if (!this.m_isBaseUrlTheRightBaseUrl) {
  65.          this.setBaseUrl();
  66.          this.m_isBaseUrlTheRightBaseUrl = true;
  67.       }
  68.  
  69.       try {
  70.          if (this.m_ProjBinder.getRelationView().getCurrentRecordState() == 105) {
  71.             this.image = null;
  72.          } else {
  73.             if (this.m_ProjBinder != null && this.m_ProjBinder.isReadable()) {
  74.                this.field_0 = this.m_ProjBinder.getBinaryStream();
  75.                Toolkit tk = ((Component)this).getToolkit();
  76.                StreamImageSource sis = new StreamImageSource(this.field_0, this.imageType);
  77.                this.image = tk.createImage(sis);
  78.                if (!this.m_displayWhileLoading) {
  79.                   this.loadImage(this.image);
  80.                   return;
  81.                }
  82.             } else {
  83.                this.image = null;
  84.             }
  85.  
  86.          }
  87.       } catch (SQLException e) {
  88.          System.out.println(((Throwable)e).getMessage());
  89.       } catch (Exception e) {
  90.          ((Throwable)e).printStackTrace();
  91.       }
  92.    }
  93.  
  94.    private void loadImage(Image image) {
  95.       if (image != null) {
  96.          try {
  97.             MediaTracker mtracker = new MediaTracker(this);
  98.             mtracker.addImage(image, 0);
  99.             mtracker.waitForID(0);
  100.          } catch (InterruptedException var3) {
  101.          }
  102.       }
  103.    }
  104.  
  105.    public void init(ProjBinder binder) {
  106.       this.m_ProjBinder = binder;
  107.    }
  108.  
  109.    public void notifyDataChange(ProjBinder binder) {
  110.       this.m_isImageTheRightImage = false;
  111.  
  112.       try {
  113.          if (this.field_0 != null) {
  114.             this.field_0.close();
  115.          }
  116.  
  117.          ((Component)this).repaint();
  118.       } catch (Exception e) {
  119.          ((Throwable)e).printStackTrace();
  120.       }
  121.    }
  122.  
  123.    public boolean notifySetData(ProjBinder binder) throws SQLException {
  124.       return true;
  125.    }
  126.  
  127.    public void paint(Graphics g) {
  128.       try {
  129.          if (!this.m_isImageTheRightImage) {
  130.             this.init();
  131.             this.m_isImageTheRightImage = true;
  132.          }
  133.  
  134.          if (this.image != null) {
  135.             g.drawImage(this.image, 0, 0, this);
  136.          }
  137.       } catch (Exception e) {
  138.          ((Throwable)e).printStackTrace();
  139.       }
  140.    }
  141.  
  142.    public void setDynamicUpdate(boolean update) {
  143.       this.m_DynamicUpdate = update;
  144.    }
  145.  
  146.    public void setTreatBlankAs(String blank) {
  147.       if ((new String(blank)).toUpperCase().equals("DEFAULT")) {
  148.          this.m_treatBlankAs = 0;
  149.       } else if ((new String(blank)).toUpperCase().equals("NULL")) {
  150.          this.m_treatBlankAs = 1;
  151.       } else {
  152.          if ((new String(blank)).toUpperCase().equals("EMPTY")) {
  153.             this.m_treatBlankAs = 2;
  154.          }
  155.  
  156.       }
  157.    }
  158.  
  159.    private void setBaseUrl() {
  160.       for(Container parent = ((Component)this).getParent(); parent != null; parent = ((Component)parent).getParent()) {
  161.          if (parent instanceof Applet) {
  162.             StreamImageSource.setBaseUrl(((Applet)parent).getCodeBase());
  163.             return;
  164.          }
  165.       }
  166.  
  167.    }
  168. }
  169.